package com.qkl.qkl.service;

import com.qkl.qkl.common.Dto;
import com.qkl.qkl.util.Conts;
import com.qkl.qkl.util.RequestDataUtil;
import com.qkl.qkl.util.SimpleHttpClient;
import org.springframework.stereotype.Service;

/**
 * 用户信息相关service
 * Created by with Intellij IDEA
 * Author : tianhaoyi
 * Date : 2018/7/20
 * Time : 9:58
 */
@Service
public class UserService {
    //注册用户
    public String userRegiest(Dto dto) throws Exception {

        String request = RequestDataUtil.generateRegisterUserRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.USER_REGISTER_URL, request);

        return result;
    }

    //获取用户信息
    public String getUserInfo(Dto dto) throws Exception {
        String request = RequestDataUtil.generateQueryAllAccountRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.GET_USERINFO_URL, request);
        return result;
    }

    //创建用户账户
    public String createUserAccount(Dto dto) throws Exception {
        String request = RequestDataUtil.generateRegisterAccountRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.CREATE_USERACCOUNT_URL, request);
        return result;
    }

    //获取用户的账户地址列表
    public String getUserAccountList(Dto dto) throws Exception {
        String request = RequestDataUtil.getUserAccountRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.GET_USERACCOUNT_LIST_URL, request);
        return result;
    }
    //获取用户的账户公钥
    public String getUserAccountPubKey(Dto dto) throws Exception {
        String request = RequestDataUtil.getUserAccountPubKeyRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.GET_USERACCOUNT_PUBKEY_URL, request);
        return result;
    }
}
